

def get_int(n): 
	s = raw_input()
	fds = s.split()
	if len(fds)!=n: 
		print 'error'
	ret = [int(i) for i in fds]
	return ret

def init_array(m, val): 
	ret = []
	for i in range(m+1): 
		ret.append(val)
	return ret

def init_matrix(n, m, val): 
	ret = []
	for i in range(n+1): 
		line = init_array(m, val)
		ret.append(line)
	return ret

def sum_line(g_sum, order, line, left, right): 
	if left==right: 
		ret = line[left]*(1<<order)
		print "ret[%d] = %d" % (left, ret)
		return ret
	if g_sum[order][left]!=-1: 
		return g_sum[order][left]

	r_left = line[left]*(1<<order)+sum_line(g_sum, order+1, line, left+1, right)
	r_right = line[right]*(1<<order)+sum_line(g_sum, order+1, line, left, right-1)
	ret = max(r_left, r_right)
	g_sum[order][left] = ret

	print "g_sum[%d][%d] = %d, left=%d, right=%d" % (order, left, ret, r_left, r_right) 

	return ret

n, m = get_int(2)
a = init_matrix(n, m, 0) 

for i in range(n): 
	line = get_int(m)
	for j in range(m): 
		a[i+1][j+1] = line[j]
#for i in range(n+1): 
#	print a[i]

a_sum = 0
for i in range(1, n+1): 
	g_sum = init_matrix(m, m, -1)
	a_sum += sum_line(g_sum, 1, a[i], 1, m)
	print "i=%d, sum=%d" % (i, a_sum)

print a_sum 


